package com.one.group.admin.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.convert.Convert;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.one.group.admin.mapper.SpChargeTypeMapper;
import com.one.group.model.dto.SpChargeTypeAddDto;
import com.one.group.model.dto.SpChargeTypeQueryDto;
import com.one.group.model.entity.SpChargeType;
import com.one.group.model.vo.SpChargeTypeVo;
import com.one.group.service.SpChargeTypeService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpChargeTypeServiceImpl extends ServiceImpl<SpChargeTypeMapper, SpChargeType> implements SpChargeTypeService {
    @Override
    public Boolean add(SpChargeTypeAddDto spChargeTypeAddDto) {
        //构建实体
        SpChargeType spChargeType = new SpChargeType();
        spChargeType.setName(spChargeTypeAddDto.getName());
        spChargeType.setRemarks(spChargeTypeAddDto.getRemarks());
        //获取租户id
        Long tenant_id = Convert.toLong(StpUtil.getExtra("tenant_id"));
        spChargeType.setTenantId(tenant_id);
        return save(spChargeType);
    }

    @Override
    public List<SpChargeTypeVo> Querylist(SpChargeTypeQueryDto spChargeTypeQueryDto) {
        //获取租户id
        Long tenant_id = Convert.toLong(StpUtil.getExtra("tenant_id"));
        spChargeTypeQueryDto.setTenantId(tenant_id);
        return this.getMapper().findByQuerylist(spChargeTypeQueryDto);
    }

    @Override
    public List<SpChargeType> findAll() {
        // 获取租户id
        Long tenantId = Convert.toLong(StpUtil.getExtra("tenant_id"));

        // 创建查询条件
        QueryWrapper queryWrapper = QueryWrapper.create().from(SpChargeType.class);
        queryWrapper.eq(SpChargeType::getTenantId, tenantId);

        // 执行查询并返回结果
        return this.getMapper().selectListByQuery(queryWrapper);

    }
}
